package com.bluetoothprint;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.bluetoothlibrary.SetBluetoothActivity;
import com.bluetoothlibrary.print.PrintUtil;
import com.commonslibrary.commons.utils.ToastUtils;
import com.tbruyelle.rxpermissions.RxPermissions;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LocalCacheUtils.getInstance().init(this);
        LocalCacheUtils.getInstance().setPrintMaxByte(32);
        findViewById(R.id.tv_print).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getPrint();
            }
        });

    }

    public void getPrint() {
        //判断是否有权限
        RxPermissions.getInstance(MainActivity.this)
                .request(Manifest.permission.ACCESS_COARSE_LOCATION)
                .subscribe(permission -> { // will emit 2 Permission objects
                    if (permission) {
                        PrintUtil.setDefaultBluetoothInfo(getApplicationContext(), getString());
                        Intent intent = new Intent(getApplicationContext(), SetBluetoothActivity.class);
                        startActivity(intent);
                    } else {
                        ToastUtils.show(MainActivity.this, "请在设置中打开拨打电话权限");
                    }
                });
    }

    public String getString() {
        StringBuffer sb = new StringBuffer();
        sb.append(TextFormatUtil.getInstance().threeStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f,"jdksfjkjkldsfkl焦点科技发快递",1f));
        sb.append(TextFormatUtil.getInstance().threeStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f,"jdksfjkjkldsfkl焦点科技发快递",1f));
        sb.append(TextFormatUtil.getInstance().threeStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f,"jdksfjkjkldsfkl焦点科技发快递",1f));
        sb.append(TextFormatUtil.getInstance().threeStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f,"jdksfjkjkldsfkl焦点科技发快递",1f));
        sb.append(TextFormatUtil.getInstance().twoStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f));
        sb.append(TextFormatUtil.getInstance().twoStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f));
        sb.append(TextFormatUtil.getInstance().twoStringAndWeight("jdksfjkjkldsfkl焦点科技发快递",1f,"dddd扣扣的开口道",1f));
        TextFormatUtil nameTitle = new TextFormatUtil();
        TextFormatUtil.threeString(nameTitle,"商品/规格","单价*数量", "金额");
        sb.append(nameTitle.endLine()+"\n");
        TextFormatUtil nameTitle1 = new TextFormatUtil();
        TextFormatUtil.threeString(nameTitle1,"商品/规格","单价*数量", "金额");
        sb.append(nameTitle1.endLine()+"\n");
        TextFormatUtil nameTitle2 = new TextFormatUtil();
        TextFormatUtil.threeString(nameTitle2,"商品/规格","单价*数量", "金额");
        sb.append(nameTitle2.endLine()+"\n");
        TextFormatUtil  formatLast = new TextFormatUtil();
        TextFormatUtil.twoString(formatLast,"商品种类："+12+"种","合计:"+33.33);
        sb.append(formatLast.endLine()+"\n");
        TextFormatUtil  formatLast1 = new TextFormatUtil();
        TextFormatUtil.twoString(formatLast1,"商品种类："+12+"种","合计:"+33.33);
        sb.append(formatLast1.endLine()+"\n");
        TextFormatUtil  formatLast2 = new TextFormatUtil();
        TextFormatUtil.twoString(formatLast2,"商品种类："+12+"种","合计:"+33.33);
        sb.append(formatLast2.endLine()+"\n");

        return  sb.toString();
    }
}
